package com.coscon.rebatesharing.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.coscon.rebatesharing.bean.TestBean;
import com.coscon.rebatesharing.dao.TestDao;
import com.coscon.rebatesharing.service.TestService;

@Service
public class TestServiceImpl implements TestService {

	@Resource
	private TestDao testDao;
	
	@Transactional(propagation=Propagation.REQUIRED)
	public void test() {
		testDao.save(new TestBean("001", "test tx"));
	}
	
	@Transactional(propagation=Propagation.REQUIRED)
	public void test1() {
		TestBean bean = testDao.get(TestBean.class, "001");
		bean.setMsg("text11111");
		testDao.update(bean);
		test2();
	}
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public void test2() {
		TestBean bean = testDao.get(TestBean.class, "001");
		bean.setMsg("text222222");
		testDao.update(bean);
		throw new RuntimeException("error");
	}
}
